(function(doc){
	var screenWidth = doc.body.clientWidth,//屏幕目宽度 chrome专用
		items = doc.querySelectorAll('.banner-item'),
		itemLen = items.length,
		wrapper = doc.querySelector('.banner-wrapper');
	wrapper.style.width = screenWidth * itemLen + 'px';
	//wrapper宽度 = 屏幕宽度 * item个数
	for(var i=0; i < itemLen; i++){
		items[i].style.width = screenWidth + 'px'		
	}//让每个item赋予屏幕宽度
	
	doc.createElement('span');
	var pagination = doc.querySelector('.pagination');

	for( var i=0; i < itemLen; i++ ){
		//items[i].style.width = screenWidth + 'px';
		pagination.appendChild(doc.createElement('a'));
	}

	doc.querySelector('.pagination a').className = 'active';
	
	

	var count = 0;
	function move(){
		if(count > itemLen - 1){
			count = 0; 
		}
		wrapper.style.left = '-' + count * screenWidth + 'px';
		count++;
		timer = setTimeout(move,2000);
	}
	var timer = setTimeout(move,0);
	var btns = doc.querySelectorAll('.pagination a'),
		btnLen = btns.length;
	for( var i = 0; i<btnLen; i++){
		btns[i].index = i;
		btns[i].onclick=function(){
			clearTimeout(timer);
			wrapper.style.left = '-' + screenWidth * this.index + 'px';
			for(var j = 0; j < btnLen; j++){
				btns[j].className = null;
			}
			this.className = 'active';
			timer = move();
		}
	}
	
})(document);


